package com.qifan.alb2b.service;

import java.util.List;

import org.springframework.stereotype.Service;

import com.qifan.alb2b.dao.CityInfoDao;
import com.qifan.alb2b.dao.CountryInfoDao;
import com.qifan.alb2b.domain.CityInfoDomain;
import com.qifan.alb2b.domain.CountryInfoDomain;
import com.qifan.alb2b.domain.HotelInfoDomain;
import com.qifan.alb2b.exception.BusinessException;
import com.qifan.alb2b.util.Constants;
import com.qifan.alb2b.util.DataGridModel;
import com.qifan.alb2b.util.Page;

/**
 * 城市业务层处理<br/>
 * 实际上对于CURD的操作本层确实有些鸡肋
 * 
 * @author hc24
 * 
 */
@Service
public class CityInfoService {
	private CityInfoDao cityInfoDao;
	private CountryInfoDao countryInfoDao;

	public void setCityInfoDao(CityInfoDao cityInfoDao) {
		this.cityInfoDao = cityInfoDao;
	}

	public void setCountryInfoDao(CountryInfoDao countryInfoDao) {
		this.countryInfoDao = countryInfoDao;
	}

	public Page query(DataGridModel dgm, CityInfoDomain cid) {
		return cityInfoDao.query(dgm, cid);
	}

	public List<CityInfoDomain> queryCityByCountry(String countryId) {
		CountryInfoDomain country= countryInfoDao.getCountryById(countryId);
		if(country==null)
			throw new BusinessException("id为"+countryId+"的国家不存在，可能已经删除");
		if(country.getStatus()==Constants.COUNTRY_CLOSE)
			throw new BusinessException("对不起,"+country.getCountryCm()+"的旅游线路还未开通");
		DataGridModel dgm = new DataGridModel();
		dgm.setRows(Integer.MAX_VALUE);
		CityInfoDomain city = new CityInfoDomain();
		city.setCountryId(countryId);
		return cityInfoDao.query(dgm, city).getRows();
	}

	public CityInfoDomain getCityById(String cid) {
		return cityInfoDao.getCityById(cid);
	}
	public CityInfoDomain getCityByCn(String cn) {
		return cityInfoDao.getCityByCn(cn);
	}

	public void add(CityInfoDomain cityInfoDomain) {
		cityInfoDao.add(cityInfoDomain);
	}

	public void update(CityInfoDomain cityInfoDomain) {
		cityInfoDao.update(cityInfoDomain);
	}

	public void delete(String[] ids) {
		cityInfoDao.delete(ids);
	}
	
public List<CityInfoDomain> queryLocationByCountry(String countryId){		
		return cityInfoDao.getLocationByCountryId(countryId);
	}
}
